const Koa = require('koa')
const app = new Koa()
const userRouter = require('./router/user.js')
const cors = require('@koa/cors')
const {bodyParser} = require('@koa/bodyparser')

// app.use(async (ctx) => {
//     if(ctx.request.url === '/home'){
//         ctx.body = '这是首页'
//     }

// })
app.use(cors())  //告诉浏览器,允许前端跨域请求我
app.use(bodyParser())  //解析请求体
//1. 被app.use调用的函数中一定拥有参数ctx
//2. userRouter.routes()就是user.js中所有的路由的回调函数
app.use(userRouter.routes(),userRouter.allowedMethods())

app.listen(3000, () => {
  console.log('server is running at http://localhost:3000')
})
